package service.impl;

import dao.ShoppingcartDao;
import dao.SubjectDao;
import dao.UserDao;
import dao.impl.ShoppingcartDaoImpl;
import dao.impl.SubjectDaoImpl;
import dao.impl.UserDaoImpl;
import model.Shoppingcart;
import service.ShoppingcartService;
import service.SubjectService;

import java.util.List;

public class ShoppingcartServiceImpl implements ShoppingcartService {

    ShoppingcartDao shoppingcartDao=new ShoppingcartDaoImpl();


    @Override
    public List<Long> getSubject(Long uid, int pageIndex, int pageSize) {
        return shoppingcartDao.find(uid,pageIndex,pageSize);
    }

    @Override
    public boolean insert(long uid, String sid) {
        if (sid == null || sid.equals("")) {
            return false;
        }
        Shoppingcart shoppingcart=new Shoppingcart();
        shoppingcart.setUid(uid);
        shoppingcart.setSid(Long.parseLong(sid));
        return shoppingcartDao.insert(shoppingcart)==1? true:false;
    }

    @Override
    public boolean delete(long uid, String sid) {
        if (sid == null || sid.equals("")) {
            return false;
        }
        Shoppingcart shoppingcart=new Shoppingcart();
        shoppingcart.setUid(uid);
        shoppingcart.setSid(Long.parseLong(sid));

        return shoppingcartDao.delete(shoppingcart)==1? true:false;
    }

    @Override
    public boolean clear(long uid) {
        return shoppingcartDao.delete(uid)>0? true:false;
    }

    @Override
    public int countById(long uid) {
        return shoppingcartDao.countById(uid);
    }

    @Override
    public List<Long> findSidByUid(long uid) {
        return shoppingcartDao.findSidByUid(uid);
    }
}
